package com.jhw.ymcc.web.controller;

import com.jhw.ymcc.exception.GlobalErrorCode;
import com.jhw.ymcc.result.JSONResult;
import com.jhw.ymcc.service.IVerifyCodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/verifycode")
public class VerifyCodeController {


    @Autowired
    private IVerifyCodeService verifyCodeService;

    @GetMapping("/imageCode/{imageCodeKey}")
    public JSONResult imageCode(@PathVariable("imageCodeKey") String imageCodeKey){
        try {
            String base64Str = verifyCodeService.getImageCode(imageCodeKey);
            return JSONResult.success(base64Str);
        }catch (Exception e){
            return JSONResult.error(GlobalErrorCode.SERVICE_PARAM_IS_NULL);
        }
    }

    @GetMapping("/sendSmsCode/{phone}")
    public JSONResult sendSmsCode(@PathVariable("phone") String phone){
        verifyCodeService.sendSmsCode(phone);
       return JSONResult.success();
    }



}